public class ObjectPrintTest {

}

class Person{
    String name;
    String gender;
    int age;

    //默认初始化
    public Person(String name,String gender,int age){
        this.name = name;
        this.gender = gender;
        this.age = age;
    }

    //右键点击Generate，选择toString
    //当我们自己实现了一个toString之后，编译器就会调用自己的toString方法
    //也可以在这个方法中写其他东西
    //@Dverride是注解，帮助检查重写的代码对不对（返回值，方法名等）
    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", gender='" + gender + '\'' +
                ", age=" + age +
                '}';
        /*return "name = " + this.name + " gender = " + this.gender + " age = " + this.age;*/
    }

    public static void main(String[] args){
        Person person = new Person("zhang san","男",18);
        System.out.println(person);
    }

}